//# sourceURL=http://uMapApp/Module/Maintain/MaintainBlock
define([
    "mhjs/mhjs"
    , "../../UI/Panel/PanelBlock/PanelBlock"
], function (
    mhjs,
    PanelBlock
) {

    function MaintainBlock(option) {

        var _this = this;
        _this.isOpened = false;

        _this.baseUrl = "/resource/G50/roadInspection/病害图片/";
        // _this.baseUrl = "";

        _this.ui = {
            maintainImg: new mhjs.Img({"class": "maintainImg"})
        };

        _this.ui.maintainImg.on("click", function () {
            if (_this.imgurl) {
                window.open(_this.imgurl);
                // if (_this.modalityWindow) {
                //     _this.modalityWindow.open(_this.imgurl, "病害图片");
                // }
            }
        });

        PanelBlock.call(_this, option);
        _this.addClass("maintainBlock propertiesBlock row");

    }

    var _class = MaintainBlock;
    mhjs.Inherit(_class, PanelBlock);


    Object.defineProperties(_class.prototype, {
        "properties"    : {
            set: function (properties) {
                var _this = this;
                _this._properties = properties;

                _this.ui.wrap.empty();

                _this.title = "病害信息";

                _this.ui.wrap
                    .append(_this.ui.maintainImg)
                    .append(_this.renderBasic())
                    .append(_this.renderRelative())
                ;


            },
            get: function () {
                return this._properties;
            }
        },
        "load"          : {
            value: function () {
                var _this = this;

                if (!_this.imgurl && _this._properties && _this._properties["图片地址"] && _this._properties["图片地址"] !== "-") {
                    _this.imgurl = _this.baseUrl + _this.properties["图片地址"];
                    _this.ui.maintainImg.attr("src", _this.imgurl);
                }

            }
        },
        "renderBasic"   : {
            value: function () {
                var _this = this;

                return _this.renderTree("基础信息", {
                    "所在道路" : _this.properties["位置"],
                    "桩号"   : _this.properties["桩号"],
                    "朝向"   : _this.properties["朝向"],
                    "车道"   : _this.properties["车道"],
                    "病害主类型": _this.properties["病害主类型"],
                    "病害子类型": _this.properties["病害子类型"],
                    "病害程度" : _this.properties["病害程度"],
                    "数据来源" : _this.properties["数据来源"],
                    "紧急程度" : _this.properties["紧急程度"]
                });

            }
        },
        "renderRelative": {
            value: function () {
                var _this = this;

                var result = _this.renderTree("巡查信息", {
                    "巡检类型": _this.properties["巡检类型"],
                    "巡查员" : _this.properties["巡查员"],
                    "巡查时间": _this.properties["巡查时间"],
                    "状态"  : _this.properties["状态"]
                });

                return result;

            }
        },
        "renderTree"    : {
            value: function (label, value) {

                var _this = this;
                var result;

                if (typeof value !== "object" || value === undefined) {
                    result = _this.renderItem(label, value);
                } else {
                    result = _this.renderFolder(label);

                    $.each(value, function (childLabel, childValue) {
                        result.child.append(_this.renderTree(childLabel, childValue));
                    });
                }

                return result;

            }
        },
        "renderFolder"  : {
            value: function (label) {

                var folder = new mhjs.Div({"class": "folder"});
                folder.label = new mhjs.Div({"class": "label"});
                folder.label.text(label);
                folder.child = new mhjs.Div({"class": "child"});

                folder
                    .append(folder.label)
                    .append(folder.child)
                ;
                return folder;
            }
        },
        "renderItem"    : {
            value: function (label, value) {

                var item = new mhjs.Div({"class": "item"});
                item.label = new mhjs.Div({"class": "label"});
                item.label.text(label);
                item.valuetext = new mhjs.Div({"class": "value"});
                item.valuetext.text(value);

                item
                    .append(item.label)
                    .append(item.valuetext)
                ;
                return item;
            }
        },
        "map"           : {
            set: function (map) {
                var _this = this;
                _this._map = new mhjs.Map(map);
            },
            get: function () {
                return this._map;
            }
        }
    });

    return _class;

});